<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /**
       * @param {number[][]} matrix
       * @return {void} Do not return anything, modify matrix in-place instead.
       */
      var rotate = function (matrix) {
        var temp = null;
        // 1.上下翻转
        for (var i = 0; i < Math.floor(matrix.length / 2); i++) {
          console.log(i);
          temp = matrix[i];
          matrix[i] = matrix[matrix.length - 1 - i];
          matrix[matrix.length - 1 - i] = temp;
        }
        // 斜对角翻转
        for (var i = 0; i < matrix.length; i++) {
          // 一层层的
          for (var j = i + 1; j < matrix.length; j++) {
            temp = matrix[i][j];
            matrix[i][j] = matrix[j][i];
            matrix[j][i] = temp;
          }
        }
        return matrix;
      };
      console.time("x");
      // 上下翻转，斜对称翻转
      var matrix = [
        [1, 2, 3],
        [4, 5, 6],
        [7, 8, 9],
      ];
      var matrix2 = [
        [5, 1, 9, 11],
        [2, 4, 8, 10],
        [13, 3, 6, 7],
        [15, 14, 12, 16],
      ];
      console.log(rotate(matrix));
      console.timeEnd("x");
    </script>
  </body>
</html>
